package com.cn.stepLock;

import com.google.gson.Gson;

import java.util.Objects;
import java.util.Optional;

/**
 * @author Aaron
 * @desc
 * @createTime 2022-02-22 5:20
 * @since
 */
public class ObjectWrapper<T> {

    private final T original;
    private T clone;

    public ObjectWrapper(T original) {
        Objects.requireNonNull(original);
        this.original = original;
    }

    public void cloneObject(){
        // 使用Gson序列化进行深拷贝
        Gson gson = new Gson();
        clone = (T)gson.fromJson(gson.toJson(original),original.getClass());
    }

    public T getOriginal() {
        return original;
    }

    public T getClone() {
        return clone;
    }
}
